#include<iostream>
#include<map>
#include<string>
using namespace std;
map<string, map<string, int> > mp;
string place, name;
int main(void) {
	int n, num;
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> name >> place >> num;
		mp[place][name] += num;
	}
	for(map<string, map<string, int> >::iterator it1 = mp.begin(); it1 != mp.end(); it1++) {
		cout << (it1->first) << endl;
		for(map<string, int>::iterator it2 = (it1->second.begin()); it2 != (it1->second.end()); it2++) {
			cout << "   |----" << it2->first << "(" << it2->second << ")" << endl;
		}
	}
	return 0;
}
